package com.lmx.repoDomain.repository;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.persistence.service.EmployeeService;
import com.lmx.repoDomain.tmodel.BackVistInfo;

import io.katharsis.repository.annotations.JsonApiResourceRepository;
import io.katharsis.repository.annotations.JsonApiSave;

@JsonApiResourceRepository(BackVistInfo.class)
@Component
public class BackVistInfoRepository extends BaseRepository<BackVistInfo> {

	@Autowired
	protected EmployeeService employeeService;

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(BackVistInfo.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	@JsonApiSave
	public BackVistInfo save(BackVistInfo info) {
		if (info.getId() == null) {
			info = employeeService.operateBackVistInfo(info);
		} else {
			if (info.getDelStatus() == 1) {// 删除
				dslJpaService.update(info);
			} else { // 修改
				info = employeeService.operateBackVistInfo(info);
			}
		}
		return info;
	}

}
